<script>
	
	export default {
		onLaunch: function(ev) {
			var self = this;
			
			var session_key = uni.getStorageSync('session_key');
			var openid = uni.getStorageSync('openid');
			uni.setStorageSync('appid',self.$request.appid);
			// #ifdef MP-WEIXIN
				uni.login({
				  provider: 'weixin',
				  success: function (e) {
					  var code = e.code;
					  console.log(code)
				   self.$request.request({
					url:'/wechat/get_openid',
					data:{'code':code},
					success:function(res){
						if(res.code==200){
							uni.setStorageSync('session_key',res.result.session_key);
							uni.setStorageSync('openid',res.result.openid);
						}else{
							uni.showToast({
								icon:"none",
								title: res.msg,
								duration: 2000
							})
						}
					}
				   })
				  }
				});
			// #endif
			let baseUrl = 'https://api.cxbyi.com';
			// #ifdef H5
			let imageBaseUrl = 'https://weizong.file.cxbyi.com/images/'
			let debug = false;
			
			let params = ev.query.params;
			let storage_params=uni.getStorageSync('params');
			if (!params && !storage_params) {
			  let currentUrl = window.location.href
			  // console.log(baseUrl + '/web/wechat/auth?redirect=' + encodeURIComponent(currentUrl))
			 window.location.href = baseUrl + '/web/wechat/auth?redirect=' + encodeURIComponent(currentUrl)
			  
			} else {
				
				if (typeof window.entryUrl === 'undefined' || window.entryUrl === '') {
				        window.entryUrl = location.href.split('#')[0];
						uni.setStorageSync('ios_wx_url',window.entryUrl);
				 }
				
				let userdata = JSON.parse(self.$request.decrypt(params));
				uni.setStorageSync('userdata',self.$request.decrypt(params));
				uni.setStorageSync('params',self.$request.decrypt(params));
				self.$request.wx_config();	
			}
			// #endif
			
			
			
			// this.$mta.App.init({
			//   	"appID":"500699093",
			//   	"autoReport": false,
			//   	"statParam": true,
			//   	"ignoreParams": [],
			// });
			this.$request.request_res({
				url:'/user/info',
				success:function(res){
					if(res.code==200){
						var  y = res.result;
						uni.setStorageSync('notice',y.unread_notice);
					}else{
						
					}
				}
			});
			setInterval(function(){
				this.$request.request_res({
					url:'/user/info',
					success:function(res){
						if(res.code==200){
							var  y = res.result;
							uni.setStorageSync('notice',y.unread_notice);
						}else{
							
						}
					}
				});
			}.bind(this),10*60*1000);
		},
		onShow: function() {
			var now_tmp = (new Date()).getTime();
			var old_tmp = uni.getStorageSync('time_tem');
			var time1 = 24 * 60 *60;
			if(old_tmp){
				if(now_tmp - old_tmp > time1){
					uni.setStorageSync('time_tem','');
					uni.setStorageSync('share_id',0);
					uni.setStorageSync('goods_id',0);
					uni.setStorageSync('note_id',0);
				}
			}
			
			
		},
		onHide: function() {
			console.log('App Hide')
		},
		onUnload:function() {
			uni.setStorageSync('search_note','')
		}
	}
</script>

<style>
	 @import './common/uni.css';
	 /* @import './common/animate.min.css'; */
	/*每个页面公共css */
	.empty-view{
		width: 100%;
		height: 140upx;
	}
	.badge_d{
		position: absolute;
		width: 10upx;
		height: 10upx;
		border-radius: 50%;
		background-color: red;
		left: 96%;
		top:20upx;
	}
	.no-msg-box{
		width: 750upx;
		padding-top: 100upx;
		text-align: center;
	}
	.no-msg{
		width: 250upx;
	}
</style>
